<?php 
function register_my_menu() {
  register_nav_menu('header-menu',__( 'Header Menu' ));
}
function t($data,$exit=1) {
	echo '<pre style="text-align:left;">';
	print_r($data);
	echo '</pre>';
	if($exit)exit;
}
function get_first_image_src($content,$type='thumb'){  
  $matches=array();
  
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
  $first_img = $matches [1] [0];
  return $first_img;
}	
function script_include(){
	wp_enqueue_script('custom_common', get_template_directory_uri() . '/js/without_jquery/common.js');
	wp_enqueue_script('first_load', get_template_directory_uri() . '/js/first_load.js', array( 'jquery' ));
		
}
function style_include(){
	global $catslug;
	if(is_home())wp_enqueue_style('home',get_template_directory_uri() . '/css/home.css',array());
	//t($catslug);
	if($catslug=='love')wp_enqueue_style('love',get_template_directory_uri() . '/css/love.css',array());
	if($catslug=='tips')wp_enqueue_style('tips',get_template_directory_uri() . '/css/tip.css',array());
	if($catslug=='handmade')wp_enqueue_style('handmade',get_template_directory_uri() . '/css/handmade.css',array());
	wp_enqueue_style('responsive',get_template_directory_uri() . '/css/responsive.css');
}
function love_style(){
	script_style();
	wp_enqueue_style('home',get_template_directory_uri() . '/css/love.css',array());
}
function tip_style(){
	script_style();
	wp_enqueue_style('home',get_template_directory_uri() . '/css/tip.css',array());
}
add_action( 'wp_enqueue_scripts', 'script_include' );
add_action( 'wp_enqueue_scripts', 'style_include' );
add_theme_support( 'post-thumbnails' );

//====================== custom post per page
$option_posts_per_page = get_option( 'posts_per_page' );
add_action( 'init', 'my_modify_posts_per_page', 0);
function my_modify_posts_per_page() {
    add_filter( 'option_posts_per_page', 'my_option_posts_per_page' );
}
function my_option_posts_per_page( $value ) {
    global $option_posts_per_page,$catobj,$catslug,$catobjparent;
	$catobj=get_category_by_slug(get_query_var('category_name'));
	$catslug=$catobj->slug;
	if($catobj->parent>0){
		$catobjparent=get_category($catobj->parent);
		$catslug=$catobjparent->slug;
	}
    if ( $catslug=='love') {
        return 6;
    } else {
        return $option_posts_per_page;
    }
}
?>